# coding=utf-8
import requests
import re

from cms import CmsSb
class Cms(object):
	header={'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'}
	def __init__(self):
		self.__cms = CmsSb()
	def cms_sbip(self,domeurl):#ip or dome
		'''

		:param domeurl: 列表
		:return:
		'''

		with open(domeurl,'r') as fo:
			for li in fo.readlines():
				ur = li.strip('\n')
				print "Dome:"+ur
				ur1 = re.findall(r"(http)",ur)#匹配网站是否有http，没有则添加头
				if ur1:#本身为False，满足条件执行
					#print '存在http'
					try:
						pd = requests.head(url=ur,allow_redirects=False,verify=False,headers=self.header)
						de = pd.status_code
					except Exception,e:
						print e
						continue
					print de
					if de == 401:
						continue
					self.__cms.Cx(line=ur,url=pd)#调用开发语言识别模块
				else:
					try:
						pd = requests.head(url="http://"+ur,allow_redirects=False,verify=False,headers=self.header)
						de = pd.status_code
					except Exception,e:
						print e
						continue
					print de
					if de == 401:
						continue
					self.__cms.Cx(line=ur,url=pd)

if __name__ == '__main__':
	cms = Cms()
	line = 'url.txt'
	cms.cms_sbip(line)

